package com.qmerak.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.qmerak.common.SysConstants;
import com.qmerak.entity.UserEntity;
import com.qmerak.service.IUserService;

/**
 * @author shaohong.cheng
 * @date 2013-4-10
 */
@Controller
@RequestMapping("/user")
@SessionAttributes("cur_user")
public class UserAction {
	@Autowired
	private IUserService service;

	@RequestMapping(value = "login", method = RequestMethod.POST)
	public String login(UserEntity user, ModelMap modelMap) {
		if (service.verify(user)) {
			modelMap.addAttribute(SysConstants.SYS_LOGIN_USER, user);
			return SysConstants.REDIRECT_PREFIX + SysConstants.SYS_MAIN_PAGE;
		} else {
			return SysConstants.SYS_LOGIN_PAGE;
		}
	}
}
